package com.codemes.happylist;

import com.codemes.happylist.modules.CodemesToolMainController;
import com.codemes.happylist.utils.SpringContextutil;
import com.codemes.happylist.modules.CodemesToolMainView;
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author nscoffee
 */
@SpringBootApplication
@Slf4j
public class CodemesToolMain extends AbstractJavaFxApplicationSupportMask {

    private static final String BASE_STYLE_CSS = "/css/baseStyle.css";
    private static final String BOOTSTRAPFX_STYLE_CSS = "/css/BootStrapFx.css";
    public static Stage mainStage;

    public static HostServices hostServices;

    CodemesToolMainController codemesToolMainController;

    @Override
    public void start(Stage stage) throws Exception {
        super.start(stage);
        CodemesToolMain.mainStage = stage;
        hostServices = getHostServices();
        stage.setTitle("爱码仕-工具包");
        if(stage.getScene()==null){
            Group group = new Group();
            group.setStyle("-fx-opacity: 0.2;");
            Scene scene=new Scene(group);
            scene.setFill(null);
            stage.setScene(scene);
        }
        stage.initStyle(StageStyle.TRANSPARENT);
        CodemesToolTray.initTray(stage);
        stage.maximizedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean t1) {
                codemesToolMainController = SpringContextutil.getBean("codemesToolMainController",CodemesToolMainController.class);
                if(Boolean.TRUE.equals(t1)){
                    codemesToolMainController.spnMain.setDividerPositions(0.15,0.85);
                }else {
                    codemesToolMainController.spnMain.setDividerPositions(0.2,0.8);
                }
            }
        });

    }
    public static void main(String[] args) {
        Platform.setImplicitExit(false);
        CodemesLaunchSplashScreen splashScreen = new CodemesLaunchSplashScreen();
        launch(CodemesToolMain.class, CodemesToolMainView.class,splashScreen, args);
    }
}
